# -*- coding: utf-8 -*-
'''
Created on 01.02.2012

@author: SkyNET
'''
import sys
import card
#args = sys.argv
cards=card.pop(7)
def flush(cards):
    a=[]
    for i in cards:
        a.append(i%10)
    f=0
    for i in a:
        if(a.count(i)>=5):
            f=1
    if(f==0):
        return []
    b=[]
    for i in range(4):
        if(a.count(i+1)>=5):
            for j in range(len(a)):
                if(i+1==a[j]):
                    b.append(cards[j])
    b.sort()
    b=b[len(b)-5:]
    b.reverse()
    return [5]+b

def streight(cards):
    cards.sort()
    cards.reverse()
    a=[]
    b=[]
    for i in cards:
        a.append(int(i/10))
    count=0
    prev=a[0]
    for i in range(1,len(a)-1):
        if(a[i]+1==prev):
            count+=1
            if(count==1):
                b.append(cards[i-1])
            b.append(cards[i])
        elif(count>=4):
            return [4]+b[:5]
        else:
            count=0
            b=[]
        prev=a[i]
    if((count==3)and(a[0]==13)):
        b.append(cards[0])
        return [4]+b
    if(count>=4):
        return [4]+b[:5]
    return []
        

def delcard(cards, what):
    a=[]
    for i in cards:
        a.append(int(i/10))
    b=[]
    for i in range(len(a)):
        if(what!=a[i]):
            b.append(cards[i])
    return b
    
def high(cards, numb):
    cards.sort()
    cards.reverse()
    cards=cards[:numb] 
    return cards

def pair(cards):
    a=[]
    for i in cards:
        a.append(int(i/10))
    b=[]
    c={}
    for i in range(len(a)):
        if(a.count(a[i])>1):
            if(b.count(a[i])==0):
                b.append(a[i])
                c[a[i]]=[]
            add=[]
            add.append(cards[i])
            c[a[i]]+=add
    b.sort()        
    b.reverse()
    pairs=[]
    set=[]
    for i in b:
        if(a.count(i)==2):
            pairs.append(i)
        if(a.count(i)==3):
            set.append(i)
        if(a.count(i)==4):
            res=[7]
            res+=c[i]
            res+=high(delcard(cards, i),1)
            return res
        
    res=[]
    if((len(pairs)>0)and(len(set)>0)):
        res.append(6)
        res+=c[set[0]]
        res+=c[pairs[0]]
        return res
    
    res=[]
    if(len(set)>0):
        res=[3]
        res+=c[set[0]]
        res+=high(delcard(cards, i),2)
        return res
    
    res=[]
    if(len(pairs)>=1):
        res.append(len(pairs))
        for i in c.keys():
            res+=c[i]
        res+=high(delcard(cards, i),5-len(pairs)*2)
        return res
    return []
    
def result(cards):
    f=flush(cards)
    s=streight(cards)
    sf
    p=pair(cards)
    if((len(f)==0)and(len(s)==0)and(len(p)==0)):
        return [0]+high(cards, 5)    
    if((f[1:]==s[1:])and(int(s[1]/10)==13)):
        res=[9]
        del s[0]
        res+=s
        return res
    if(f[1:]==s[1:]):
        res=[8]
        del s[0]
        res+=s
        return res
    if(len(p)>0):
        if(p[0]==7):
            return p
        if(p[0]==6):
            return p
    if(len(f)>0):
        return f
    if(len(s)>0):
        return s
    if(len(p)>0):
        return p

print cards
print result([133, 103, 113, 93, 83, 34, 124])
          
